﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Steve.UI.Controllers;
using System.Web.Mvc;
using System.ComponentModel.Composition;
using Microsoft.ComponentModel.Composition.Extensions.Web;
using Steve.UI.Models;

namespace Steve.UI.Site.Controllers
{
    [Export(typeof(IController))]
    [ExportMetadata("Name", "Content")]
    [ExportMetadata("Mode", WebScopeMode.Request)]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    [SiteMasterData]
    [Authorize]
    public class ContentController : ContentControllerBase
    {
        
        public override ActionResult Data(Guid id, int? revision = null, bool approvedOnly = true, bool raw = false, bool markRead = true)
        {
            if (!approvedOnly && !User.IsInRoles("Steve-Content Reader", "Steve-Sys Admin")) throw new HttpException(403, "Unauthorized");

            return base.Data(id, revision, approvedOnly, markRead);
        }

        public override ActionResult RenderUrl(bool approvedOnly = true, bool markRead = true)
        {
            if (!approvedOnly && !User.IsInRoles("Steve-Content Reader", "Steve-Sys Admin")) throw new HttpException(403, "Unauthorized");

            return base.RenderUrl(approvedOnly, markRead);
        }

        public override ActionResult SimilarContent(Guid id, string contentTypeName = null, bool approvedOnly = true, bool hideRead = true, int count = 10)
        {
            if (!approvedOnly && !User.IsInRoles("Steve-Content Reader", "Steve-Sys Admin")) throw new HttpException(403, "Unauthorized");

            return base.SimilarContent(id, contentTypeName, approvedOnly, hideRead, count);
        }

        public override ActionResult SimilarContent(IEnumerable<string> requiredCategoryNames, IEnumerable<string> optionalCategoryNames, string contentTypeName = null, bool approvedOnly = true, bool hideRead = true, int count = 10)
        {
            if (!approvedOnly && !User.IsInRoles("Steve-Content Reader", "Steve-Sys Admin")) throw new HttpException(403, "Unauthorized");

            return base.SimilarContent(requiredCategoryNames, optionalCategoryNames, contentTypeName, approvedOnly, hideRead, count);
        }

        public override ActionResult SearchResults(SearchModel model)
        {
            if (model.SearchType != SearchType.LatestApproved && !User.IsInRoles("Steve-Content Reader", "Steve-Sys Admin")) throw new HttpException(403, "Unauthorized");

            return base.SearchResults(model);
        }
    }
}